# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/16 20:04 
@Author  : ZhangShenao 
@File    : side_effect.py 
@Desc    : Mock Side Effect机制

side effect指的是:mock的函数,属性是可以根据不同的输入,返回不同的数值,而不只是一个 return_value
"""
from unittest.mock import MagicMock


def side_effect(arg: int) -> int:
    if arg < 0:
        return 1
    return 2


if __name__ == '__main__':
    mock = MagicMock()
    mock.side_effect = side_effect
    print(mock(-1))  # 1
    print(mock(1))  # 2
